<template>
  <div>
    <h2>人员列表</h2>
    <p>
      <input type="text" v-model="name" placeholder="请输入内容" />
      <button @click="add">按钮</button>
    </p>
    <ul>
      <li v-for="p in personList" :key="p.id">
        {{ p.name }}
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  data() {
    return {
      name: "",
    };
  },
  computed: {
    personList() {
      return this.$store.state.personList;
    },
  },
  methods: {
    add() {
      // id是唯一的字符串 后面跟着是数字或字符串不相同的数字或字符串
      let personObj = { id: Date.now(), name: this.name };
      this.$store.commit("ADD_PERSON", personObj);
      //   清空数据
      this.name = "";
    },
  },
};
</script>

<style>
</style>